package 线程池;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolExecutorDemo {

    public static void main(String[] args) {
        //创建一个线程池：开了一个快递公司
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                5,
                10,
                60,
                TimeUnit.SECONDS,
                //一般不使用无边界的阻塞队列：因为内存有限
                new ArrayBlockingQueue<>(10000),
                //拒绝策略：一般最多使用CallerRunsPolicy，或自己实现
                new ThreadPoolExecutor.AbortPolicy()
        );

        pool.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println("hello");
            }
        });
    }
}
